cmake_minimum_required(VERSION 3.10)

message(STATUS "Running quick install of pipfreeze...")

# 检查缓存是否已存在
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/build/CMakeCache.txt")
    message(STATUS "CMake cache found. Skipping configuration step.")
else()
    message(STATUS "No CMake cache found. Configuring project...")
    execute_process(
        COMMAND ${CMAKE_COMMAND} -S . -B build -DCMAKE_INSTALL_PREFIX=$ENV{HOME}/.local
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
    )
endif()

# 构建
execute_process(
    COMMAND ${CMAKE_COMMAND} --build build
    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

# 安装
execute_process(
    COMMAND ${CMAKE_COMMAND} --install build
    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

message(STATUS "✅ pipfreeze installed to ~/.local/bin")
